<?php

// Global variable for table object
$presu_presupuestos = NULL;

//
// Table class for presu_presupuestos
//
class cpresu_presupuestos extends cTable {
	var $PresuId;
	var $PresuFechaCopia;
	var $PresuEstado;
	var $PresuFacturaPto;
	var $PresuFacturoTipo;
	var $PresuFacturaNumero;
	var $PresuMotivo;
	var $PresFechaCierre;
	var $PresuReemplazado;
	var $PresuSucursal;
	var $PresuEmpresa;
	var $PresuTip;
	var $PresuLet;
	var $PresuPun;
	var $PresuNum;
	var $PresuCli;
	var $PresuRaz;
	var $PresuFec1;
	var $PresuVen;
	var $PresuTot;
	var $PresuEntDir;
	var $PresuEntLoc;
	var $PresuEntTel;
	var $PresuEntEmail;
	var $PresuEntObs1;
	var $PresuEntObs2;
	var $PresuHor;
	var $PresuTipoCli;
	var $PresuFechaUltimaGestion;
	var $PresuProximoContacto;

	//
	// Table class constructor
	//
	function __construct() {
		global $Language;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();
		$this->TableVar = 'presu_presupuestos';
		$this->TableName = 'presu_presupuestos';
		$this->TableType = 'TABLE';
		$this->ExportAll = TRUE;
		$this->ExportPageBreakCount = 0; // Page break per every n record (PDF only)
		$this->ExportPageOrientation = "portrait"; // Page orientation (PDF only)
		$this->ExportPageSize = "a4"; // Page size (PDF only)
		$this->DetailAdd = FALSE; // Allow detail add
		$this->DetailEdit = FALSE; // Allow detail edit
		$this->DetailView = FALSE; // Allow detail view
		$this->ShowMultipleDetails = FALSE; // Show multiple details
		$this->GridAddRowCount = 5;
		$this->AllowAddDeleteRow = ew_AllowAddDeleteRow(); // Allow add/delete row
		$this->UserIDAllowSecurity = 0; // User ID Allow
		$this->BasicSearch = new cBasicSearch($this->TableVar);

		// PresuId
		$this->PresuId = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuId', 'PresuId', '`PresuId`', '`PresuId`', 3, -1, FALSE, '`PresuId`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuId->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuId'] = &$this->PresuId;

		// PresuFechaCopia
		$this->PresuFechaCopia = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuFechaCopia', 'PresuFechaCopia', '`PresuFechaCopia`', 'DATE_FORMAT(`PresuFechaCopia`, \'%d/%m/%Y\')', 135, 7, FALSE, '`PresuFechaCopia`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuFechaCopia->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateDMY"));
		$this->fields['PresuFechaCopia'] = &$this->PresuFechaCopia;

		// PresuEstado
		$this->PresuEstado = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEstado', 'PresuEstado', '`PresuEstado`', '`PresuEstado`', 3, -1, FALSE, '`PresuEstado`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuEstado->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuEstado'] = &$this->PresuEstado;

		// PresuFacturaPto
		$this->PresuFacturaPto = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuFacturaPto', 'PresuFacturaPto', '`PresuFacturaPto`', '`PresuFacturaPto`', 3, -1, FALSE, '`PresuFacturaPto`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuFacturaPto->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuFacturaPto'] = &$this->PresuFacturaPto;

		// PresuFacturoTipo
		$this->PresuFacturoTipo = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuFacturoTipo', 'PresuFacturoTipo', '`PresuFacturoTipo`', '`PresuFacturoTipo`', 200, -1, FALSE, '`PresuFacturoTipo`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuFacturoTipo'] = &$this->PresuFacturoTipo;

		// PresuFacturaNumero
		$this->PresuFacturaNumero = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuFacturaNumero', 'PresuFacturaNumero', '`PresuFacturaNumero`', '`PresuFacturaNumero`', 3, -1, FALSE, '`PresuFacturaNumero`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuFacturaNumero->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuFacturaNumero'] = &$this->PresuFacturaNumero;

		// PresuMotivo
		$this->PresuMotivo = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuMotivo', 'PresuMotivo', '`PresuMotivo`', '`PresuMotivo`', 3, -1, FALSE, '`PresuMotivo`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuMotivo->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuMotivo'] = &$this->PresuMotivo;

		// PresFechaCierre
		$this->PresFechaCierre = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresFechaCierre', 'PresFechaCierre', '`PresFechaCierre`', 'DATE_FORMAT(`PresFechaCierre`, \'%d/%m/%Y\')', 135, 7, FALSE, '`PresFechaCierre`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresFechaCierre->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateDMY"));
		$this->fields['PresFechaCierre'] = &$this->PresFechaCierre;

		// PresuReemplazado
		$this->PresuReemplazado = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuReemplazado', 'PresuReemplazado', '`PresuReemplazado`', '`PresuReemplazado`', 3, -1, FALSE, '`PresuReemplazado`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuReemplazado->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuReemplazado'] = &$this->PresuReemplazado;

		// PresuSucursal
		$this->PresuSucursal = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuSucursal', 'PresuSucursal', '`PresuSucursal`', '`PresuSucursal`', 3, -1, FALSE, '`PresuSucursal`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuSucursal->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuSucursal'] = &$this->PresuSucursal;

		// PresuEmpresa
		$this->PresuEmpresa = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEmpresa', 'PresuEmpresa', '`PresuEmpresa`', '`PresuEmpresa`', 3, -1, FALSE, '`PresuEmpresa`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuEmpresa->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuEmpresa'] = &$this->PresuEmpresa;

		// PresuTip
		$this->PresuTip = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuTip', 'PresuTip', '`PresuTip`', '`PresuTip`', 200, -1, FALSE, '`PresuTip`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuTip'] = &$this->PresuTip;

		// PresuLet
		$this->PresuLet = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuLet', 'PresuLet', '`PresuLet`', '`PresuLet`', 200, -1, FALSE, '`PresuLet`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuLet'] = &$this->PresuLet;

		// PresuPun
		$this->PresuPun = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuPun', 'PresuPun', '`PresuPun`', '`PresuPun`', 3, -1, FALSE, '`PresuPun`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuPun->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuPun'] = &$this->PresuPun;

		// PresuNum
		$this->PresuNum = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuNum', 'PresuNum', '`PresuNum`', '`PresuNum`', 3, -1, FALSE, '`PresuNum`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuNum->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuNum'] = &$this->PresuNum;

		// PresuCli
		$this->PresuCli = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuCli', 'PresuCli', '`PresuCli`', '`PresuCli`', 3, -1, FALSE, '`PresuCli`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuCli->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuCli'] = &$this->PresuCli;

		// PresuRaz
		$this->PresuRaz = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuRaz', 'PresuRaz', '`PresuRaz`', '`PresuRaz`', 200, -1, FALSE, '`PresuRaz`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuRaz'] = &$this->PresuRaz;

		// PresuFec1
		$this->PresuFec1 = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuFec1', 'PresuFec1', '`PresuFec1`', 'DATE_FORMAT(`PresuFec1`, \'%d/%m/%Y\')', 133, 7, FALSE, '`PresuFec1`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuFec1->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateDMY"));
		$this->fields['PresuFec1'] = &$this->PresuFec1;

		// PresuVen
		$this->PresuVen = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuVen', 'PresuVen', '`PresuVen`', '`PresuVen`', 3, -1, FALSE, '`PresuVen`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuVen->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuVen'] = &$this->PresuVen;

		// PresuTot
		$this->PresuTot = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuTot', 'PresuTot', '`PresuTot`', '`PresuTot`', 131, -1, FALSE, '`PresuTot`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuTot->FldDefaultErrMsg = $Language->Phrase("IncorrectFloat");
		$this->fields['PresuTot'] = &$this->PresuTot;

		// PresuEntDir
		$this->PresuEntDir = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEntDir', 'PresuEntDir', '`PresuEntDir`', '`PresuEntDir`', 200, -1, FALSE, '`PresuEntDir`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuEntDir'] = &$this->PresuEntDir;

		// PresuEntLoc
		$this->PresuEntLoc = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEntLoc', 'PresuEntLoc', '`PresuEntLoc`', '`PresuEntLoc`', 200, -1, FALSE, '`PresuEntLoc`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuEntLoc'] = &$this->PresuEntLoc;

		// PresuEntTel
		$this->PresuEntTel = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEntTel', 'PresuEntTel', '`PresuEntTel`', '`PresuEntTel`', 200, -1, FALSE, '`PresuEntTel`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuEntTel'] = &$this->PresuEntTel;

		// PresuEntEmail
		$this->PresuEntEmail = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEntEmail', 'PresuEntEmail', '`PresuEntEmail`', '`PresuEntEmail`', 200, -1, FALSE, '`PresuEntEmail`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuEntEmail'] = &$this->PresuEntEmail;

		// PresuEntObs1
		$this->PresuEntObs1 = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEntObs1', 'PresuEntObs1', '`PresuEntObs1`', '`PresuEntObs1`', 200, -1, FALSE, '`PresuEntObs1`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuEntObs1'] = &$this->PresuEntObs1;

		// PresuEntObs2
		$this->PresuEntObs2 = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuEntObs2', 'PresuEntObs2', '`PresuEntObs2`', '`PresuEntObs2`', 200, -1, FALSE, '`PresuEntObs2`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->fields['PresuEntObs2'] = &$this->PresuEntObs2;

		// PresuHor
		$this->PresuHor = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuHor', 'PresuHor', '`PresuHor`', '`PresuHor`', 3, -1, FALSE, '`PresuHor`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuHor->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuHor'] = &$this->PresuHor;

		// PresuTipoCli
		$this->PresuTipoCli = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuTipoCli', 'PresuTipoCli', '`PresuTipoCli`', '`PresuTipoCli`', 3, -1, FALSE, '`PresuTipoCli`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuTipoCli->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
		$this->fields['PresuTipoCli'] = &$this->PresuTipoCli;

		// PresuFechaUltimaGestion
		$this->PresuFechaUltimaGestion = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuFechaUltimaGestion', 'PresuFechaUltimaGestion', '`PresuFechaUltimaGestion`', 'DATE_FORMAT(`PresuFechaUltimaGestion`, \'%d/%m/%Y\')', 133, 7, FALSE, '`PresuFechaUltimaGestion`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuFechaUltimaGestion->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateDMY"));
		$this->fields['PresuFechaUltimaGestion'] = &$this->PresuFechaUltimaGestion;

		// PresuProximoContacto
		$this->PresuProximoContacto = new cField('presu_presupuestos', 'presu_presupuestos', 'x_PresuProximoContacto', 'PresuProximoContacto', '`PresuProximoContacto`', 'DATE_FORMAT(`PresuProximoContacto`, \'%d/%m/%Y\')', 133, 7, FALSE, '`PresuProximoContacto`', FALSE, FALSE, FALSE, 'FORMATTED TEXT');
		$this->PresuProximoContacto->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateDMY"));
		$this->fields['PresuProximoContacto'] = &$this->PresuProximoContacto;
	}

	// Single column sort
	function UpdateSort(&$ofld) {
		if ($this->CurrentOrder == $ofld->FldName) {
			$sSortField = $ofld->FldExpression;
			$sLastSort = $ofld->getSort();
			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
				$sThisSort = $this->CurrentOrderType;
			} else {
				$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			}
			$ofld->setSort($sThisSort);
			$this->setSessionOrderBy($sSortField . " " . $sThisSort); // Save to Session
		} else {
			$ofld->setSort("");
		}
	}

	// Table level SQL
	function SqlFrom() { // From
		return "`presu_presupuestos`";
	}

	function SqlSelect() { // Select
		return "SELECT * FROM " . $this->SqlFrom();
	}

	function SqlWhere() { // Where
		$sWhere = "";
		$this->TableFilter = "";
		ew_AddFilter($sWhere, $this->TableFilter);
		return $sWhere;
	}

	function SqlGroupBy() { // Group By
		return "";
	}

	function SqlHaving() { // Having
		return "";
	}

	function SqlOrderBy() { // Order By
		return "";
	}

	// Check if Anonymous User is allowed
	function AllowAnonymousUser() {
		switch (@$this->PageID) {
			case "add":
			case "register":
			case "addopt":
				return FALSE;
			case "edit":
			case "update":
			case "changepwd":
			case "forgotpwd":
				return FALSE;
			case "delete":
				return FALSE;
			case "view":
				return FALSE;
			case "search":
				return FALSE;
			default:
				return FALSE;
		}
	}

	// Apply User ID filters
	function ApplyUserIDFilters($sFilter) {
		return $sFilter;
	}

	// Check if User ID security allows view all
	function UserIDAllow($id = "") {
		$allow = EW_USER_ID_ALLOW;
		switch ($id) {
			case "add":
			case "copy":
			case "gridadd":
			case "register":
			case "addopt":
				return (($allow & 1) == 1);
			case "edit":
			case "gridedit":
			case "update":
			case "changepwd":
			case "forgotpwd":
				return (($allow & 4) == 4);
			case "delete":
				return (($allow & 2) == 2);
			case "view":
				return (($allow & 32) == 32);
			case "search":
				return (($allow & 64) == 64);
			default:
				return (($allow & 8) == 8);
		}
	}

	// Get SQL
	function GetSQL($where, $orderby) {
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$where, $orderby);
	}

	// Table SQL
	function SQL() {
		$sFilter = $this->CurrentFilter;
		$sFilter = $this->ApplyUserIDFilters($sFilter);
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$sFilter, $sSort);
	}

	// Table SQL with List page filter
	function SelectSQL() {
		$sFilter = $this->getSessionWhere();
		ew_AddFilter($sFilter, $this->CurrentFilter);
		$sFilter = $this->ApplyUserIDFilters($sFilter);
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(), $this->SqlGroupBy(),
			$this->SqlHaving(), $this->SqlOrderBy(), $sFilter, $sSort);
	}

	// Get ORDER BY clause
	function GetOrderBy() {
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql("", "", "", "", $this->SqlOrderBy(), "", $sSort);
	}

	// Try to get record count
	function TryGetRecordCount($sSql) {
		global $conn;
		$cnt = -1;
		if ($this->TableType == 'TABLE' || $this->TableType == 'VIEW') {
			$sSql = "SELECT COUNT(*) FROM" . preg_replace('/^SELECT\s([\s\S]+)?\*\sFROM/i', "", $sSql);
			$sOrderBy = $this->GetOrderBy();
			if (substr($sSql, strlen($sOrderBy) * -1) == $sOrderBy)
				$sSql = substr($sSql, 0, strlen($sSql) - strlen($sOrderBy)); // Remove ORDER BY clause
		} else {
			$sSql = "SELECT COUNT(*) FROM (" . $sSql . ") EW_COUNT_TABLE";
		}
		if ($rs = $conn->Execute($sSql)) {
			if (!$rs->EOF && $rs->FieldCount() > 0) {
				$cnt = $rs->fields[0];
				$rs->Close();
			}
		}
		return intval($cnt);
	}

	// Get record count based on filter (for detail record count in master table pages)
	function LoadRecordCount($sFilter) {
		$origFilter = $this->CurrentFilter;
		$this->CurrentFilter = $sFilter;
		$this->Recordset_Selecting($this->CurrentFilter);

		//$sSql = $this->SQL();
		$sSql = $this->GetSQL($this->CurrentFilter, "");
		$cnt = $this->TryGetRecordCount($sSql);
		if ($cnt == -1) {
			if ($rs = $this->LoadRs($this->CurrentFilter)) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// Get record count (for current List page)
	function SelectRecordCount() {
		global $conn;
		$origFilter = $this->CurrentFilter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$sSql = $this->SelectSQL();
		$cnt = $this->TryGetRecordCount($sSql);
		if ($cnt == -1) {
			if ($rs = $conn->Execute($sSql)) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// Update Table
	var $UpdateTable = "`presu_presupuestos`";

	// INSERT statement
	function InsertSQL(&$rs) {
		global $conn;
		$names = "";
		$values = "";
		foreach ($rs as $name => $value) {
			if (!isset($this->fields[$name]))
				continue;
			$names .= $this->fields[$name]->FldExpression . ",";
			$values .= ew_QuotedValue($value, $this->fields[$name]->FldDataType) . ",";
		}
		while (substr($names, -1) == ",")
			$names = substr($names, 0, -1);
		while (substr($values, -1) == ",")
			$values = substr($values, 0, -1);
		return "INSERT INTO " . $this->UpdateTable . " ($names) VALUES ($values)";
	}

	// Insert
	function Insert(&$rs) {
		global $conn;
		return $conn->Execute($this->InsertSQL($rs));
	}

	// UPDATE statement
	function UpdateSQL(&$rs, $where = "") {
		$sql = "UPDATE " . $this->UpdateTable . " SET ";
		foreach ($rs as $name => $value) {
			if (!isset($this->fields[$name]))
				continue;
			$sql .= $this->fields[$name]->FldExpression . "=";
			$sql .= ew_QuotedValue($value, $this->fields[$name]->FldDataType) . ",";
		}
		while (substr($sql, -1) == ",")
			$sql = substr($sql, 0, -1);
		$filter = $this->CurrentFilter;
		ew_AddFilter($filter, $where);
		if ($filter <> "")	$sql .= " WHERE " . $filter;
		return $sql;
	}

	// Update
	function Update(&$rs, $where = "", $rsold = NULL) {
		global $conn;
		return $conn->Execute($this->UpdateSQL($rs, $where));
	}

	// DELETE statement
	function DeleteSQL(&$rs, $where = "") {
		$sql = "DELETE FROM " . $this->UpdateTable . " WHERE ";
		if ($rs) {
			if (array_key_exists('PresuId', $rs))
				ew_AddFilter($where, ew_QuotedName('PresuId') . '=' . ew_QuotedValue($rs['PresuId'], $this->PresuId->FldDataType));
		}
		$filter = $this->CurrentFilter;
		ew_AddFilter($filter, $where);
		if ($filter <> "")
			$sql .= $filter;
		else
			$sql .= "0=1"; // Avoid delete
		return $sql;
	}

	// Delete
	function Delete(&$rs, $where = "") {
		global $conn;
		return $conn->Execute($this->DeleteSQL($rs, $where));
	}

	// Key filter WHERE clause
	function SqlKeyFilter() {
		return "`PresuId` = @PresuId@";
	}

	// Key filter
	function KeyFilter() {
		$sKeyFilter = $this->SqlKeyFilter();
		if (!is_numeric($this->PresuId->CurrentValue))
			$sKeyFilter = "0=1"; // Invalid key
		$sKeyFilter = str_replace("@PresuId@", ew_AdjustSql($this->PresuId->CurrentValue), $sKeyFilter); // Replace key value
		return $sKeyFilter;
	}

	// Return page URL
	function getReturnUrl() {
		$name = EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL;

		// Get referer URL automatically
		if (ew_ServerVar("HTTP_REFERER") <> "" && ew_ReferPage() <> ew_CurrentPage() && ew_ReferPage() <> "login.php") // Referer not same page or login page
			$_SESSION[$name] = ew_ServerVar("HTTP_REFERER"); // Save to Session
		if (@$_SESSION[$name] <> "") {
			return $_SESSION[$name];
		} else {
			return "presu_presupuestoslist.php";
		}
	}

	function setReturnUrl($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL] = $v;
	}

	// List URL
	function GetListUrl() {
		return "presu_presupuestoslist.php";
	}

	// View URL
	function GetViewUrl($parm = "") {
		if ($parm <> "")
			return $this->KeyUrl("presu_presupuestosview.php", $this->UrlParm($parm));
		else
			return $this->KeyUrl("presu_presupuestosview.php", $this->UrlParm(EW_TABLE_SHOW_DETAIL . "="));
	}

	// Add URL
	function GetAddUrl() {
		return "presu_presupuestosadd.php";
	}

	// Edit URL
	function GetEditUrl($parm = "") {
		return $this->KeyUrl("presu_presupuestosedit.php", $this->UrlParm($parm));
	}

	// Inline edit URL
	function GetInlineEditUrl() {
		return $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=edit"));
	}

	// Copy URL
	function GetCopyUrl($parm = "") {
		return $this->KeyUrl("presu_presupuestosadd.php", $this->UrlParm($parm));
	}

	// Inline copy URL
	function GetInlineCopyUrl() {
		return $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=copy"));
	}

	// Delete URL
	function GetDeleteUrl() {
		return $this->KeyUrl("presu_presupuestosdelete.php", $this->UrlParm());
	}

	// Add key value to URL
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->PresuId->CurrentValue)) {
			$sUrl .= "PresuId=" . urlencode($this->PresuId->CurrentValue);
		} else {
			return "javascript:alert(ewLanguage.Phrase('InvalidRecord'));";
		}
		return $sUrl;
	}

	// Sort URL
	function SortUrl(&$fld) {
		if ($this->CurrentAction <> "" || $this->Export <> "" ||
			in_array($fld->FldType, array(128, 204, 205))) { // Unsortable data type
				return "";
		} elseif ($fld->Sortable) {
			$sUrlParm = $this->UrlParm("order=" . urlencode($fld->FldName) . "&amp;ordertype=" . $fld->ReverseSort());
			return ew_CurrentPage() . "?" . $sUrlParm;
		} else {
			return "";
		}
	}

	// Get record keys from $_POST/$_GET/$_SESSION
	function GetRecordKeys() {
		global $EW_COMPOSITE_KEY_SEPARATOR;
		$arKeys = array();
		$arKey = array();
		if (isset($_POST["key_m"])) {
			$arKeys = ew_StripSlashes($_POST["key_m"]);
			$cnt = count($arKeys);
		} elseif (isset($_GET["key_m"])) {
			$arKeys = ew_StripSlashes($_GET["key_m"]);
			$cnt = count($arKeys);
		} elseif (isset($_GET)) {
			$arKeys[] = @$_GET["PresuId"]; // PresuId

			//return $arKeys; // Do not return yet, so the values will also be checked by the following code
		}

		// Check keys
		$ar = array();
		foreach ($arKeys as $key) {
			if (!is_numeric($key))
				continue;
			$ar[] = $key;
		}
		return $ar;
	}

	// Get key filter
	function GetKeyFilter() {
		$arKeys = $this->GetRecordKeys();
		$sKeyFilter = "";
		foreach ($arKeys as $key) {
			if ($sKeyFilter <> "") $sKeyFilter .= " OR ";
			$this->PresuId->CurrentValue = $key;
			$sKeyFilter .= "(" . $this->KeyFilter() . ")";
		}
		return $sKeyFilter;
	}

	// Load rows based on filter
	function &LoadRs($sFilter) {
		global $conn;

		// Set up filter (SQL WHERE clause) and get return SQL
		//$this->CurrentFilter = $sFilter;
		//$sSql = $this->SQL();

		$sSql = $this->GetSQL($sFilter, "");
		$rs = $conn->Execute($sSql);
		return $rs;
	}

	// Load row values from recordset
	function LoadListRowValues(&$rs) {
		$this->PresuId->setDbValue($rs->fields('PresuId'));
		$this->PresuFechaCopia->setDbValue($rs->fields('PresuFechaCopia'));
		$this->PresuEstado->setDbValue($rs->fields('PresuEstado'));
		$this->PresuFacturaPto->setDbValue($rs->fields('PresuFacturaPto'));
		$this->PresuFacturoTipo->setDbValue($rs->fields('PresuFacturoTipo'));
		$this->PresuFacturaNumero->setDbValue($rs->fields('PresuFacturaNumero'));
		$this->PresuMotivo->setDbValue($rs->fields('PresuMotivo'));
		$this->PresFechaCierre->setDbValue($rs->fields('PresFechaCierre'));
		$this->PresuReemplazado->setDbValue($rs->fields('PresuReemplazado'));
		$this->PresuSucursal->setDbValue($rs->fields('PresuSucursal'));
		$this->PresuEmpresa->setDbValue($rs->fields('PresuEmpresa'));
		$this->PresuTip->setDbValue($rs->fields('PresuTip'));
		$this->PresuLet->setDbValue($rs->fields('PresuLet'));
		$this->PresuPun->setDbValue($rs->fields('PresuPun'));
		$this->PresuNum->setDbValue($rs->fields('PresuNum'));
		$this->PresuCli->setDbValue($rs->fields('PresuCli'));
		$this->PresuRaz->setDbValue($rs->fields('PresuRaz'));
		$this->PresuFec1->setDbValue($rs->fields('PresuFec1'));
		$this->PresuVen->setDbValue($rs->fields('PresuVen'));
		$this->PresuTot->setDbValue($rs->fields('PresuTot'));
		$this->PresuEntDir->setDbValue($rs->fields('PresuEntDir'));
		$this->PresuEntLoc->setDbValue($rs->fields('PresuEntLoc'));
		$this->PresuEntTel->setDbValue($rs->fields('PresuEntTel'));
		$this->PresuEntEmail->setDbValue($rs->fields('PresuEntEmail'));
		$this->PresuEntObs1->setDbValue($rs->fields('PresuEntObs1'));
		$this->PresuEntObs2->setDbValue($rs->fields('PresuEntObs2'));
		$this->PresuHor->setDbValue($rs->fields('PresuHor'));
		$this->PresuTipoCli->setDbValue($rs->fields('PresuTipoCli'));
		$this->PresuFechaUltimaGestion->setDbValue($rs->fields('PresuFechaUltimaGestion'));
		$this->PresuProximoContacto->setDbValue($rs->fields('PresuProximoContacto'));
	}

	// Render list row values
	function RenderListRow() {
		global $conn, $Security, $gsLanguage;

		// Call Row Rendering event
		$this->Row_Rendering();

   // Common render codes
		// PresuId
		// PresuFechaCopia
		// PresuEstado
		// PresuFacturaPto
		// PresuFacturoTipo
		// PresuFacturaNumero
		// PresuMotivo
		// PresFechaCierre
		// PresuReemplazado
		// PresuSucursal
		// PresuEmpresa
		// PresuTip
		// PresuLet
		// PresuPun
		// PresuNum
		// PresuCli
		// PresuRaz
		// PresuFec1
		// PresuVen
		// PresuTot
		// PresuEntDir
		// PresuEntLoc
		// PresuEntTel
		// PresuEntEmail
		// PresuEntObs1
		// PresuEntObs2
		// PresuHor
		// PresuTipoCli
		// PresuFechaUltimaGestion
		// PresuProximoContacto
		// PresuId

		$this->PresuId->ViewValue = $this->PresuId->CurrentValue;
		$this->PresuId->ViewCustomAttributes = "";

		// PresuFechaCopia
		$this->PresuFechaCopia->ViewValue = $this->PresuFechaCopia->CurrentValue;
		$this->PresuFechaCopia->ViewValue = ew_FormatDateTime($this->PresuFechaCopia->ViewValue, 7);
		$this->PresuFechaCopia->ViewCustomAttributes = "";

		// PresuEstado
		$this->PresuEstado->ViewValue = $this->PresuEstado->CurrentValue;
		$this->PresuEstado->ViewCustomAttributes = "";

		// PresuFacturaPto
		$this->PresuFacturaPto->ViewValue = $this->PresuFacturaPto->CurrentValue;
		$this->PresuFacturaPto->ViewCustomAttributes = "";

		// PresuFacturoTipo
		$this->PresuFacturoTipo->ViewValue = $this->PresuFacturoTipo->CurrentValue;
		$this->PresuFacturoTipo->ViewCustomAttributes = "";

		// PresuFacturaNumero
		$this->PresuFacturaNumero->ViewValue = $this->PresuFacturaNumero->CurrentValue;
		$this->PresuFacturaNumero->ViewCustomAttributes = "";

		// PresuMotivo
		$this->PresuMotivo->ViewValue = $this->PresuMotivo->CurrentValue;
		$this->PresuMotivo->ViewCustomAttributes = "";

		// PresFechaCierre
		$this->PresFechaCierre->ViewValue = $this->PresFechaCierre->CurrentValue;
		$this->PresFechaCierre->ViewValue = ew_FormatDateTime($this->PresFechaCierre->ViewValue, 7);
		$this->PresFechaCierre->ViewCustomAttributes = "";

		// PresuReemplazado
		$this->PresuReemplazado->ViewValue = $this->PresuReemplazado->CurrentValue;
		$this->PresuReemplazado->ViewCustomAttributes = "";

		// PresuSucursal
		$this->PresuSucursal->ViewValue = $this->PresuSucursal->CurrentValue;
		$this->PresuSucursal->ViewCustomAttributes = "";

		// PresuEmpresa
		$this->PresuEmpresa->ViewValue = $this->PresuEmpresa->CurrentValue;
		$this->PresuEmpresa->ViewCustomAttributes = "";

		// PresuTip
		$this->PresuTip->ViewValue = $this->PresuTip->CurrentValue;
		$this->PresuTip->ViewCustomAttributes = "";

		// PresuLet
		$this->PresuLet->ViewValue = $this->PresuLet->CurrentValue;
		$this->PresuLet->ViewCustomAttributes = "";

		// PresuPun
		$this->PresuPun->ViewValue = $this->PresuPun->CurrentValue;
		$this->PresuPun->ViewCustomAttributes = "";

		// PresuNum
		$this->PresuNum->ViewValue = $this->PresuNum->CurrentValue;
		$this->PresuNum->ViewCustomAttributes = "";

		// PresuCli
		$this->PresuCli->ViewValue = $this->PresuCli->CurrentValue;
		$this->PresuCli->ViewCustomAttributes = "";

		// PresuRaz
		$this->PresuRaz->ViewValue = $this->PresuRaz->CurrentValue;
		$this->PresuRaz->ViewCustomAttributes = "";

		// PresuFec1
		$this->PresuFec1->ViewValue = $this->PresuFec1->CurrentValue;
		$this->PresuFec1->ViewValue = ew_FormatDateTime($this->PresuFec1->ViewValue, 7);
		$this->PresuFec1->ViewCustomAttributes = "";

		// PresuVen
		$this->PresuVen->ViewValue = $this->PresuVen->CurrentValue;
		$this->PresuVen->ViewCustomAttributes = "";

		// PresuTot
		$this->PresuTot->ViewValue = $this->PresuTot->CurrentValue;
		$this->PresuTot->ViewCustomAttributes = "";

		// PresuEntDir
		$this->PresuEntDir->ViewValue = $this->PresuEntDir->CurrentValue;
		$this->PresuEntDir->ViewCustomAttributes = "";

		// PresuEntLoc
		$this->PresuEntLoc->ViewValue = $this->PresuEntLoc->CurrentValue;
		$this->PresuEntLoc->ViewCustomAttributes = "";

		// PresuEntTel
		$this->PresuEntTel->ViewValue = $this->PresuEntTel->CurrentValue;
		$this->PresuEntTel->ViewCustomAttributes = "";

		// PresuEntEmail
		$this->PresuEntEmail->ViewValue = $this->PresuEntEmail->CurrentValue;
		$this->PresuEntEmail->ViewCustomAttributes = "";

		// PresuEntObs1
		$this->PresuEntObs1->ViewValue = $this->PresuEntObs1->CurrentValue;
		$this->PresuEntObs1->ViewCustomAttributes = "";

		// PresuEntObs2
		$this->PresuEntObs2->ViewValue = $this->PresuEntObs2->CurrentValue;
		$this->PresuEntObs2->ViewCustomAttributes = "";

		// PresuHor
		$this->PresuHor->ViewValue = $this->PresuHor->CurrentValue;
		$this->PresuHor->ViewCustomAttributes = "";

		// PresuTipoCli
		$this->PresuTipoCli->ViewValue = $this->PresuTipoCli->CurrentValue;
		$this->PresuTipoCli->ViewCustomAttributes = "";

		// PresuFechaUltimaGestion
		$this->PresuFechaUltimaGestion->ViewValue = $this->PresuFechaUltimaGestion->CurrentValue;
		$this->PresuFechaUltimaGestion->ViewValue = ew_FormatDateTime($this->PresuFechaUltimaGestion->ViewValue, 7);
		$this->PresuFechaUltimaGestion->ViewCustomAttributes = "";

		// PresuProximoContacto
		$this->PresuProximoContacto->ViewValue = $this->PresuProximoContacto->CurrentValue;
		$this->PresuProximoContacto->ViewValue = ew_FormatDateTime($this->PresuProximoContacto->ViewValue, 7);
		$this->PresuProximoContacto->ViewCustomAttributes = "";

		// PresuId
		$this->PresuId->LinkCustomAttributes = "";
		$this->PresuId->HrefValue = "";
		$this->PresuId->TooltipValue = "";

		// PresuFechaCopia
		$this->PresuFechaCopia->LinkCustomAttributes = "";
		$this->PresuFechaCopia->HrefValue = "";
		$this->PresuFechaCopia->TooltipValue = "";

		// PresuEstado
		$this->PresuEstado->LinkCustomAttributes = "";
		$this->PresuEstado->HrefValue = "";
		$this->PresuEstado->TooltipValue = "";

		// PresuFacturaPto
		$this->PresuFacturaPto->LinkCustomAttributes = "";
		$this->PresuFacturaPto->HrefValue = "";
		$this->PresuFacturaPto->TooltipValue = "";

		// PresuFacturoTipo
		$this->PresuFacturoTipo->LinkCustomAttributes = "";
		$this->PresuFacturoTipo->HrefValue = "";
		$this->PresuFacturoTipo->TooltipValue = "";

		// PresuFacturaNumero
		$this->PresuFacturaNumero->LinkCustomAttributes = "";
		$this->PresuFacturaNumero->HrefValue = "";
		$this->PresuFacturaNumero->TooltipValue = "";

		// PresuMotivo
		$this->PresuMotivo->LinkCustomAttributes = "";
		$this->PresuMotivo->HrefValue = "";
		$this->PresuMotivo->TooltipValue = "";

		// PresFechaCierre
		$this->PresFechaCierre->LinkCustomAttributes = "";
		$this->PresFechaCierre->HrefValue = "";
		$this->PresFechaCierre->TooltipValue = "";

		// PresuReemplazado
		$this->PresuReemplazado->LinkCustomAttributes = "";
		$this->PresuReemplazado->HrefValue = "";
		$this->PresuReemplazado->TooltipValue = "";

		// PresuSucursal
		$this->PresuSucursal->LinkCustomAttributes = "";
		$this->PresuSucursal->HrefValue = "";
		$this->PresuSucursal->TooltipValue = "";

		// PresuEmpresa
		$this->PresuEmpresa->LinkCustomAttributes = "";
		$this->PresuEmpresa->HrefValue = "";
		$this->PresuEmpresa->TooltipValue = "";

		// PresuTip
		$this->PresuTip->LinkCustomAttributes = "";
		$this->PresuTip->HrefValue = "";
		$this->PresuTip->TooltipValue = "";

		// PresuLet
		$this->PresuLet->LinkCustomAttributes = "";
		$this->PresuLet->HrefValue = "";
		$this->PresuLet->TooltipValue = "";

		// PresuPun
		$this->PresuPun->LinkCustomAttributes = "";
		$this->PresuPun->HrefValue = "";
		$this->PresuPun->TooltipValue = "";

		// PresuNum
		$this->PresuNum->LinkCustomAttributes = "";
		$this->PresuNum->HrefValue = "";
		$this->PresuNum->TooltipValue = "";

		// PresuCli
		$this->PresuCli->LinkCustomAttributes = "";
		$this->PresuCli->HrefValue = "";
		$this->PresuCli->TooltipValue = "";

		// PresuRaz
		$this->PresuRaz->LinkCustomAttributes = "";
		$this->PresuRaz->HrefValue = "";
		$this->PresuRaz->TooltipValue = "";

		// PresuFec1
		$this->PresuFec1->LinkCustomAttributes = "";
		$this->PresuFec1->HrefValue = "";
		$this->PresuFec1->TooltipValue = "";

		// PresuVen
		$this->PresuVen->LinkCustomAttributes = "";
		$this->PresuVen->HrefValue = "";
		$this->PresuVen->TooltipValue = "";

		// PresuTot
		$this->PresuTot->LinkCustomAttributes = "";
		$this->PresuTot->HrefValue = "";
		$this->PresuTot->TooltipValue = "";

		// PresuEntDir
		$this->PresuEntDir->LinkCustomAttributes = "";
		$this->PresuEntDir->HrefValue = "";
		$this->PresuEntDir->TooltipValue = "";

		// PresuEntLoc
		$this->PresuEntLoc->LinkCustomAttributes = "";
		$this->PresuEntLoc->HrefValue = "";
		$this->PresuEntLoc->TooltipValue = "";

		// PresuEntTel
		$this->PresuEntTel->LinkCustomAttributes = "";
		$this->PresuEntTel->HrefValue = "";
		$this->PresuEntTel->TooltipValue = "";

		// PresuEntEmail
		$this->PresuEntEmail->LinkCustomAttributes = "";
		$this->PresuEntEmail->HrefValue = "";
		$this->PresuEntEmail->TooltipValue = "";

		// PresuEntObs1
		$this->PresuEntObs1->LinkCustomAttributes = "";
		$this->PresuEntObs1->HrefValue = "";
		$this->PresuEntObs1->TooltipValue = "";

		// PresuEntObs2
		$this->PresuEntObs2->LinkCustomAttributes = "";
		$this->PresuEntObs2->HrefValue = "";
		$this->PresuEntObs2->TooltipValue = "";

		// PresuHor
		$this->PresuHor->LinkCustomAttributes = "";
		$this->PresuHor->HrefValue = "";
		$this->PresuHor->TooltipValue = "";

		// PresuTipoCli
		$this->PresuTipoCli->LinkCustomAttributes = "";
		$this->PresuTipoCli->HrefValue = "";
		$this->PresuTipoCli->TooltipValue = "";

		// PresuFechaUltimaGestion
		$this->PresuFechaUltimaGestion->LinkCustomAttributes = "";
		$this->PresuFechaUltimaGestion->HrefValue = "";
		$this->PresuFechaUltimaGestion->TooltipValue = "";

		// PresuProximoContacto
		$this->PresuProximoContacto->LinkCustomAttributes = "";
		$this->PresuProximoContacto->HrefValue = "";
		$this->PresuProximoContacto->TooltipValue = "";

		// Call Row Rendered event
		$this->Row_Rendered();
	}

	// Aggregate list row values
	function AggregateListRowValues() {
	}

	// Aggregate list row (for rendering)
	function AggregateListRow() {
	}

	// Export data in HTML/CSV/Word/Excel/Email/PDF format
	function ExportDocument(&$Doc, &$Recordset, $StartRec, $StopRec, $ExportPageType = "") {
		if (!$Recordset || !$Doc)
			return;

		// Write header
		$Doc->ExportTableHeader();
		if ($Doc->Horizontal) { // Horizontal format, write header
			$Doc->BeginExportRow();
			if ($ExportPageType == "view") {
				if ($this->PresuId->Exportable) $Doc->ExportCaption($this->PresuId);
				if ($this->PresuFechaCopia->Exportable) $Doc->ExportCaption($this->PresuFechaCopia);
				if ($this->PresuEstado->Exportable) $Doc->ExportCaption($this->PresuEstado);
				if ($this->PresuFacturaPto->Exportable) $Doc->ExportCaption($this->PresuFacturaPto);
				if ($this->PresuFacturoTipo->Exportable) $Doc->ExportCaption($this->PresuFacturoTipo);
				if ($this->PresuFacturaNumero->Exportable) $Doc->ExportCaption($this->PresuFacturaNumero);
				if ($this->PresuMotivo->Exportable) $Doc->ExportCaption($this->PresuMotivo);
				if ($this->PresFechaCierre->Exportable) $Doc->ExportCaption($this->PresFechaCierre);
				if ($this->PresuReemplazado->Exportable) $Doc->ExportCaption($this->PresuReemplazado);
				if ($this->PresuSucursal->Exportable) $Doc->ExportCaption($this->PresuSucursal);
				if ($this->PresuEmpresa->Exportable) $Doc->ExportCaption($this->PresuEmpresa);
				if ($this->PresuTip->Exportable) $Doc->ExportCaption($this->PresuTip);
				if ($this->PresuLet->Exportable) $Doc->ExportCaption($this->PresuLet);
				if ($this->PresuPun->Exportable) $Doc->ExportCaption($this->PresuPun);
				if ($this->PresuNum->Exportable) $Doc->ExportCaption($this->PresuNum);
				if ($this->PresuCli->Exportable) $Doc->ExportCaption($this->PresuCli);
				if ($this->PresuRaz->Exportable) $Doc->ExportCaption($this->PresuRaz);
				if ($this->PresuFec1->Exportable) $Doc->ExportCaption($this->PresuFec1);
				if ($this->PresuVen->Exportable) $Doc->ExportCaption($this->PresuVen);
				if ($this->PresuTot->Exportable) $Doc->ExportCaption($this->PresuTot);
				if ($this->PresuEntDir->Exportable) $Doc->ExportCaption($this->PresuEntDir);
				if ($this->PresuEntLoc->Exportable) $Doc->ExportCaption($this->PresuEntLoc);
				if ($this->PresuEntTel->Exportable) $Doc->ExportCaption($this->PresuEntTel);
				if ($this->PresuEntEmail->Exportable) $Doc->ExportCaption($this->PresuEntEmail);
				if ($this->PresuEntObs1->Exportable) $Doc->ExportCaption($this->PresuEntObs1);
				if ($this->PresuEntObs2->Exportable) $Doc->ExportCaption($this->PresuEntObs2);
				if ($this->PresuHor->Exportable) $Doc->ExportCaption($this->PresuHor);
				if ($this->PresuTipoCli->Exportable) $Doc->ExportCaption($this->PresuTipoCli);
				if ($this->PresuFechaUltimaGestion->Exportable) $Doc->ExportCaption($this->PresuFechaUltimaGestion);
				if ($this->PresuProximoContacto->Exportable) $Doc->ExportCaption($this->PresuProximoContacto);
			} else {
				if ($this->PresuId->Exportable) $Doc->ExportCaption($this->PresuId);
				if ($this->PresuFechaCopia->Exportable) $Doc->ExportCaption($this->PresuFechaCopia);
				if ($this->PresuEstado->Exportable) $Doc->ExportCaption($this->PresuEstado);
				if ($this->PresuFacturaPto->Exportable) $Doc->ExportCaption($this->PresuFacturaPto);
				if ($this->PresuFacturoTipo->Exportable) $Doc->ExportCaption($this->PresuFacturoTipo);
				if ($this->PresuFacturaNumero->Exportable) $Doc->ExportCaption($this->PresuFacturaNumero);
				if ($this->PresuMotivo->Exportable) $Doc->ExportCaption($this->PresuMotivo);
				if ($this->PresFechaCierre->Exportable) $Doc->ExportCaption($this->PresFechaCierre);
				if ($this->PresuReemplazado->Exportable) $Doc->ExportCaption($this->PresuReemplazado);
				if ($this->PresuSucursal->Exportable) $Doc->ExportCaption($this->PresuSucursal);
				if ($this->PresuEmpresa->Exportable) $Doc->ExportCaption($this->PresuEmpresa);
				if ($this->PresuTip->Exportable) $Doc->ExportCaption($this->PresuTip);
				if ($this->PresuLet->Exportable) $Doc->ExportCaption($this->PresuLet);
				if ($this->PresuPun->Exportable) $Doc->ExportCaption($this->PresuPun);
				if ($this->PresuNum->Exportable) $Doc->ExportCaption($this->PresuNum);
				if ($this->PresuCli->Exportable) $Doc->ExportCaption($this->PresuCli);
				if ($this->PresuRaz->Exportable) $Doc->ExportCaption($this->PresuRaz);
				if ($this->PresuFec1->Exportable) $Doc->ExportCaption($this->PresuFec1);
				if ($this->PresuVen->Exportable) $Doc->ExportCaption($this->PresuVen);
				if ($this->PresuTot->Exportable) $Doc->ExportCaption($this->PresuTot);
				if ($this->PresuEntDir->Exportable) $Doc->ExportCaption($this->PresuEntDir);
				if ($this->PresuEntLoc->Exportable) $Doc->ExportCaption($this->PresuEntLoc);
				if ($this->PresuEntTel->Exportable) $Doc->ExportCaption($this->PresuEntTel);
				if ($this->PresuEntEmail->Exportable) $Doc->ExportCaption($this->PresuEntEmail);
				if ($this->PresuEntObs1->Exportable) $Doc->ExportCaption($this->PresuEntObs1);
				if ($this->PresuEntObs2->Exportable) $Doc->ExportCaption($this->PresuEntObs2);
				if ($this->PresuHor->Exportable) $Doc->ExportCaption($this->PresuHor);
				if ($this->PresuTipoCli->Exportable) $Doc->ExportCaption($this->PresuTipoCli);
				if ($this->PresuFechaUltimaGestion->Exportable) $Doc->ExportCaption($this->PresuFechaUltimaGestion);
				if ($this->PresuProximoContacto->Exportable) $Doc->ExportCaption($this->PresuProximoContacto);
			}
			$Doc->EndExportRow();
		}

		// Move to first record
		$RecCnt = $StartRec - 1;
		if (!$Recordset->EOF) {
			$Recordset->MoveFirst();
			if ($StartRec > 1)
				$Recordset->Move($StartRec - 1);
		}
		while (!$Recordset->EOF && $RecCnt < $StopRec) {
			$RecCnt++;
			if (intval($RecCnt) >= intval($StartRec)) {
				$RowCnt = intval($RecCnt) - intval($StartRec) + 1;

				// Page break
				if ($this->ExportPageBreakCount > 0) {
					if ($RowCnt > 1 && ($RowCnt - 1) % $this->ExportPageBreakCount == 0)
						$Doc->ExportPageBreak();
				}
				$this->LoadListRowValues($Recordset);

				// Render row
				$this->RowType = EW_ROWTYPE_VIEW; // Render view
				$this->ResetAttrs();
				$this->RenderListRow();
				$Doc->BeginExportRow($RowCnt); // Allow CSS styles if enabled
				if ($ExportPageType == "view") {
					if ($this->PresuId->Exportable) $Doc->ExportField($this->PresuId);
					if ($this->PresuFechaCopia->Exportable) $Doc->ExportField($this->PresuFechaCopia);
					if ($this->PresuEstado->Exportable) $Doc->ExportField($this->PresuEstado);
					if ($this->PresuFacturaPto->Exportable) $Doc->ExportField($this->PresuFacturaPto);
					if ($this->PresuFacturoTipo->Exportable) $Doc->ExportField($this->PresuFacturoTipo);
					if ($this->PresuFacturaNumero->Exportable) $Doc->ExportField($this->PresuFacturaNumero);
					if ($this->PresuMotivo->Exportable) $Doc->ExportField($this->PresuMotivo);
					if ($this->PresFechaCierre->Exportable) $Doc->ExportField($this->PresFechaCierre);
					if ($this->PresuReemplazado->Exportable) $Doc->ExportField($this->PresuReemplazado);
					if ($this->PresuSucursal->Exportable) $Doc->ExportField($this->PresuSucursal);
					if ($this->PresuEmpresa->Exportable) $Doc->ExportField($this->PresuEmpresa);
					if ($this->PresuTip->Exportable) $Doc->ExportField($this->PresuTip);
					if ($this->PresuLet->Exportable) $Doc->ExportField($this->PresuLet);
					if ($this->PresuPun->Exportable) $Doc->ExportField($this->PresuPun);
					if ($this->PresuNum->Exportable) $Doc->ExportField($this->PresuNum);
					if ($this->PresuCli->Exportable) $Doc->ExportField($this->PresuCli);
					if ($this->PresuRaz->Exportable) $Doc->ExportField($this->PresuRaz);
					if ($this->PresuFec1->Exportable) $Doc->ExportField($this->PresuFec1);
					if ($this->PresuVen->Exportable) $Doc->ExportField($this->PresuVen);
					if ($this->PresuTot->Exportable) $Doc->ExportField($this->PresuTot);
					if ($this->PresuEntDir->Exportable) $Doc->ExportField($this->PresuEntDir);
					if ($this->PresuEntLoc->Exportable) $Doc->ExportField($this->PresuEntLoc);
					if ($this->PresuEntTel->Exportable) $Doc->ExportField($this->PresuEntTel);
					if ($this->PresuEntEmail->Exportable) $Doc->ExportField($this->PresuEntEmail);
					if ($this->PresuEntObs1->Exportable) $Doc->ExportField($this->PresuEntObs1);
					if ($this->PresuEntObs2->Exportable) $Doc->ExportField($this->PresuEntObs2);
					if ($this->PresuHor->Exportable) $Doc->ExportField($this->PresuHor);
					if ($this->PresuTipoCli->Exportable) $Doc->ExportField($this->PresuTipoCli);
					if ($this->PresuFechaUltimaGestion->Exportable) $Doc->ExportField($this->PresuFechaUltimaGestion);
					if ($this->PresuProximoContacto->Exportable) $Doc->ExportField($this->PresuProximoContacto);
				} else {
					if ($this->PresuId->Exportable) $Doc->ExportField($this->PresuId);
					if ($this->PresuFechaCopia->Exportable) $Doc->ExportField($this->PresuFechaCopia);
					if ($this->PresuEstado->Exportable) $Doc->ExportField($this->PresuEstado);
					if ($this->PresuFacturaPto->Exportable) $Doc->ExportField($this->PresuFacturaPto);
					if ($this->PresuFacturoTipo->Exportable) $Doc->ExportField($this->PresuFacturoTipo);
					if ($this->PresuFacturaNumero->Exportable) $Doc->ExportField($this->PresuFacturaNumero);
					if ($this->PresuMotivo->Exportable) $Doc->ExportField($this->PresuMotivo);
					if ($this->PresFechaCierre->Exportable) $Doc->ExportField($this->PresFechaCierre);
					if ($this->PresuReemplazado->Exportable) $Doc->ExportField($this->PresuReemplazado);
					if ($this->PresuSucursal->Exportable) $Doc->ExportField($this->PresuSucursal);
					if ($this->PresuEmpresa->Exportable) $Doc->ExportField($this->PresuEmpresa);
					if ($this->PresuTip->Exportable) $Doc->ExportField($this->PresuTip);
					if ($this->PresuLet->Exportable) $Doc->ExportField($this->PresuLet);
					if ($this->PresuPun->Exportable) $Doc->ExportField($this->PresuPun);
					if ($this->PresuNum->Exportable) $Doc->ExportField($this->PresuNum);
					if ($this->PresuCli->Exportable) $Doc->ExportField($this->PresuCli);
					if ($this->PresuRaz->Exportable) $Doc->ExportField($this->PresuRaz);
					if ($this->PresuFec1->Exportable) $Doc->ExportField($this->PresuFec1);
					if ($this->PresuVen->Exportable) $Doc->ExportField($this->PresuVen);
					if ($this->PresuTot->Exportable) $Doc->ExportField($this->PresuTot);
					if ($this->PresuEntDir->Exportable) $Doc->ExportField($this->PresuEntDir);
					if ($this->PresuEntLoc->Exportable) $Doc->ExportField($this->PresuEntLoc);
					if ($this->PresuEntTel->Exportable) $Doc->ExportField($this->PresuEntTel);
					if ($this->PresuEntEmail->Exportable) $Doc->ExportField($this->PresuEntEmail);
					if ($this->PresuEntObs1->Exportable) $Doc->ExportField($this->PresuEntObs1);
					if ($this->PresuEntObs2->Exportable) $Doc->ExportField($this->PresuEntObs2);
					if ($this->PresuHor->Exportable) $Doc->ExportField($this->PresuHor);
					if ($this->PresuTipoCli->Exportable) $Doc->ExportField($this->PresuTipoCli);
					if ($this->PresuFechaUltimaGestion->Exportable) $Doc->ExportField($this->PresuFechaUltimaGestion);
					if ($this->PresuProximoContacto->Exportable) $Doc->ExportField($this->PresuProximoContacto);
				}
				$Doc->EndExportRow();
			}
			$Recordset->MoveNext();
		}
		$Doc->ExportTableFooter();
	}

	// Table level events
	// Recordset Selecting event
	function Recordset_Selecting(&$filter) {

		// Enter your code here	
	}

	// Recordset Selected event
	function Recordset_Selected(&$rs) {

		//echo "Recordset Selected";
	}

	// Recordset Search Validated event
	function Recordset_SearchValidated() {

		// Example:
		//$this->MyField1->AdvancedSearch->SearchValue = "your search criteria"; // Search value

	}

	// Recordset Searching event
	function Recordset_Searching(&$filter) {

		// Enter your code here	
	}

	// Row_Selecting event
	function Row_Selecting(&$filter) {

		// Enter your code here	
	}

	// Row Selected event
	function Row_Selected(&$rs) {

		//echo "Row Selected";
	}

	// Row Inserting event
	function Row_Inserting($rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Inserted event
	function Row_Inserted($rsold, &$rsnew) {

		//echo "Row Inserted"
	}

	// Row Updating event
	function Row_Updating($rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Updated event
	function Row_Updated($rsold, &$rsnew) {

		//echo "Row Updated";
	}

	// Row Update Conflict event
	function Row_UpdateConflict($rsold, &$rsnew) {

		// Enter your code here
		// To ignore conflict, set return value to FALSE

		return TRUE;
	}

	// Row Deleting event
	function Row_Deleting(&$rs) {

		// Enter your code here
		// To cancel, set return value to False

		return TRUE;
	}

	// Row Deleted event
	function Row_Deleted(&$rs) {

		//echo "Row Deleted";
	}

	// Email Sending event
	function Email_Sending(&$Email, &$Args) {

		//var_dump($Email); var_dump($Args); exit();
		return TRUE;
	}

	// Lookup Selecting event
	function Lookup_Selecting($fld, &$filter) {

		// Enter your code here
	}

	// Row Rendering event
	function Row_Rendering() {

		// Enter your code here	
	}

	// Row Rendered event
	function Row_Rendered() {

		// To view properties of field class, use:
		//var_dump($this-><FieldName>); 

	}

	// User ID Filtering event
	function UserID_Filtering(&$filter) {

		// Enter your code here
	}
}
?>
